<template>

	<view>
		<view class="lineH2"></view>
		<view class="uni-padding-wrap uni-common-mt">
			<input class="uni-input" placeholder="请输入手机号码" :value="phone" @input="phoneChange" />
			<view class="lineH1"></view>
			<!-- <view class="uni-flex uni-row">
				<input class="uni-input" placeholder="请输入验证码" :value="vcode" @input="vcodeChange" />
				<label class="pcode" @tap="getVcode">获取验证码</label>
			</view>
			<view class="lineH1"></view> -->
			<button type="primary" @tap="updatePhone">修改电话号码</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone: '',
				vcode: '111111',
			};
		},
		methods: {
			phoneChange: function(e) {
				this.phone = e.target.value
			},
			vcodeChange: function(e) {
				this.vcode = e.target.value
			},
			getVcode() { //获取短信验证码
				if (this.phone.length == 0) {
					uni.showToast({
						title: '手机号不正确',
						icon: 'none',
						duration: 1500
					});
					return;
				}
				this.$http.post('ac/xagrid/appVerCodeService/getVerCode', {
					type: '1',
					mobile: this.phone,
				}).then((res) => {
					if (res.errcode === '0') { //0成功  1失败
						//短信验证码
						this.vcode='111111';
						uni.showToast({
							title: '验证码获取成功',
							mask: false,
							duration: 1500
						});
					} else {
						uni.showToast({
							title: res.errmsg,
							icon: 'none',
							duration: 1500
						});
					}
				});
			},
			updatePhone() { //修改手机号
				const _phone = this.phone,
					_vcode = this.vcode;
				if (_phone.length == 0) {
					uni.showToast({
						title: '手机号不正确',
						icon: 'none',
						duration: 1500
					});
					return;
				}
				if (_vcode.length == 0) {
					uni.showToast({
						title: '验证码不正确',
						icon: 'none',
						duration: 1500
					});
					return;
				}
				this.$http.get('ac/xagrid/appUserService/updatePhone', {
					mobile: _phone,
					verCode: _vcode,
				}).then((res) => {
					if (res.errcode === '0') { //0成功  1失败
						uni.showToast({
							title: res.errmsg,
							mask: false,
							duration: 1500
						});
						getApp().globalData.mobile=_phone;
						this.setTime();
					} else {
						uni.showToast({
							title: res.errmsg,
							icon: 'none',
							duration: 1500
						});
					}
				});
			},
			setTime() {
				setTimeout(function() {
					uni.navigateBack(); //数据回显
				}, 1000 * 2);
			},
		}
	}
</script>

<style>
	.lineH1 {
		height: 2upx;
		width: 100%;
		/* margin-left: 10upx; */
		background-color: #F7F7F7;
	}

	.lineH2 {
		height: 32upx;
		width: 100%;
		background-color: #F7F7F7;
	}

	.pcode {
		padding: 20upx;
		background-color: #FFFFFF;
		color: #007AFF;
	}

	button {
		margin-top: 32upx;
	}

	.update-phone-bg {
		background-color: #FFFFFF;
		margin-top: 200upx;
	}
</style>
